package com.shujia.MR.partitions;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * 将学生数据按男女性别分别写入至两个文件中
 */

public class PartitionDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJobName("ScoreCount");
        job.setJarByClass(PartitionDriver.class);

        job.setMapperClass(PartitionMapper.class);
        job.setReducerClass(PartitionReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Student.class);
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Student.class);


        job.setNumReduceTasks(2);
        // 设置自定义分区类
        job.setPartitionerClass(MyPartition.class);

        FileInputFormat.addInputPath(job, new Path("D:\\workspace19\\HadoopCode\\data\\Join"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\workspace19\\HadoopCode\\output\\partition"));

        job.waitForCompletion(true);
    }
}
